package com.zkyc.framework.algorithm.service;

import com.zkyc.framework.algorithm.bean.SenstiveFactory;
import com.zkyc.framework.algorithm.mapper.WordSenstiveMapper;
import com.zkyc.framework.common.pojo.WordSenstive;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @author bing.bai
 * @create 2022/5/18
 */
@Service
@Slf4j
public class SenstiveWordService {

    @Autowired
    private WordSenstiveMapper wordSenstiveMapper;

    public Set<String> senstiveWordCheck(String text) {
        text = Jsoup.clean(text, Whitelist.none());
        return SenstiveFactory.checkSensitiveWord(text, 2);
    }

    public void senstiveWordRefresh() {
        List<WordSenstive> wordSenstives = wordSenstiveMapper.selectList(null);
        SenstiveFactory.initSensitiveWordMap(wordSenstives);
    }
}
